package fun.coding.leetcode;

import java.util.HashMap;

public class TwoSum {

	public static void main(String[] args) {
		
	}

	public int[] twoSum(int[] numbers, int target) {
    	if (numbers == null || numbers.length < 2) {
    		return null;
    	}
    	
    	HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    	
    	for (int i = 0; i < numbers.length; ++i) {
    		if (map.containsKey(target - numbers[i])) {
    			int[] res = new int[2];
    			res[0] = map.get(target-numbers[i]) + 1;
    			res[1] = i + 1;
    			return res;
    		}
    		
    		map.put(numbers[i], i);
    	}
    	return null;
    }
}
